package com.echo.register.commons.config;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @program: com.echo.voter
 * @description: 自定义interceptor
 * @author: Xiaoti
 * @create: 2018-11-02 10:06
 **/
public class VoteInterceptor implements HandlerInterceptor {

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Override
    public void postHandle(HttpServletRequest request,
                           HttpServletResponse response, Object handler,
                           ModelAndView modelAndView) throws Exception {

    }
    @Override
    public void afterCompletion(HttpServletRequest request,
                                HttpServletResponse response, Object handler, Exception ex)
            throws Exception {
        CookieHolder.remove();
    }
    @Override
    public boolean preHandle(HttpServletRequest request,
                             HttpServletResponse response, Object handler) throws Exception {

//        Cookie cookie = CommonUtils.getCookie(request, VoteSerivce.COOKIE_UM_TOKEN);
//        if(cookie == null){
//            return true;
//        }
//        CookieHolder.add(cookie);
//        logger.info("VoteInterceptor cookie's value is {}", cookie.getValue());

        return true;
    }
}
